package edu.ecnu.yt.spring.di.conditional;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class CheckMyEnvCondition implements Condition {

	public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
		String envName = context.getEnvironment().getProperty("myEnv.name");
		boolean isTestBean = "testBean".equals(
				((String[]) metadata
				.getAnnotationAttributes("org.springframework.context.annotation.Bean")
				.get("name"))[0]
			);
		return "myEnvName".equals(envName) && isTestBean;
		
	}

}
